// 主题接口
class Subject {
    request () {
        console.log('处理请求')
    }
}

// 具体主题
class RealSubject extends Subject {
    request () {
        console.log('具体主题处理请求')
    }
}

// 代理
class Proxy extends Subject {
    constructor(subject) {
        super()
        this.realSubject = subject
    }
    request () {
        if (this.checkAccess()) {
            this.realSubject.request()
            this.logAccess()
        }
    }
    checkAccess () {
        console.log('检查访问权限')
        return true
    }
    logAccess () {
        console.log('记录访问日志')
    }
}

// 使用代理访问真实对象
const realSubject = new RealSubject()
const proxy = new Proxy(realSubject)

proxy.request()
